﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Xml;


namespace SMS.SysManage
{
    public partial class frmVoiceSetting : Form
    {
        #region 常量变量枚举类型定义
        /// <summary>
        /// Form Load Flag
        /// </summary>
        //private Boolean blnLoadFlg = false;
        #endregion 常量变量枚举类型定义

        /// <summary>
        /// 构造函数
        /// </summary>
        public frmVoiceSetting()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Form Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmVoiceSetting_Load(object sender, EventArgs e)
        {
            bool blnVoiceOpenFlg = SMS.Properties.Settings.Default.VOICE_OPEN;
            int intVoiceRate = SMS.Properties.Settings.Default.VOICE_RATE;
            int intVoiceVolume = SMS.Properties.Settings.Default.VOICE_VOLUME / 10;

            // 显示语音开关
            this.rdbVoiceOpen.Checked = blnVoiceOpenFlg;
            this.rdbVoiceClose.Checked = !blnVoiceOpenFlg;

            // 显示语速
            this.tkbRate.Enabled = blnVoiceOpenFlg;
            this.lblRateValue.Text = intVoiceRate.ToString();
            this.tkbRate.Value = intVoiceRate;

            // 显示音量
            this.lblVolume.Text = intVoiceVolume.ToString();
            this.tkbVolume.Value = intVoiceVolume;

        }

        /// <summary>
        /// 打开按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVoiceOpen_Click(object sender, EventArgs e)
        {
            this.SettingChanged();
        }

        /// <summary>
        /// 关闭按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVoiceStop_Click(object sender, EventArgs e)
        {
            this.SettingChanged();
        }

        /// <summary>
        /// 语音开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rdbVoiceOpen_CheckedChanged(object sender, EventArgs e)
        {
            this.SettingChanged();
        }

        /// <summary>
        /// 语音关
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rdbVoiceClose_CheckedChanged(object sender, EventArgs e)
        {
            this.SettingChanged();
        }

        /// <summary>
        /// 语音开关
        /// </summary>
        private void SettingChanged()
        {
            bool blnVoiceOpenFlg = this.rdbVoiceOpen.Checked;

            this.rdbVoiceOpen.Checked = blnVoiceOpenFlg;
            this.rdbVoiceClose.Checked = !blnVoiceOpenFlg;
            this.tkbRate.Enabled = blnVoiceOpenFlg;

            SMS.Properties.Settings.Default.VOICE_OPEN = blnVoiceOpenFlg;
            SMS.Properties.Settings.Default.Save();
        }

        /// <summary>
        /// 语速控件滚动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tkbRate_Scroll(object sender, EventArgs e)
        {
            this.lblRateValue.Text = (this.tkbRate.Value - 5).ToString();
        }

        /// <summary>
        /// 语速值改变完了事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tkbRate_ValueChanged(object sender, EventArgs e)
        {
            SMS.Properties.Settings.Default.VOICE_RATE = this.tkbRate.Value;
            SMS.Properties.Settings.Default.Save();
        }

        /// <summary>
        /// 音量控件滚动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tkbVolume_Scroll(object sender, EventArgs e)
        {
            this.lblVolume.Text = this.tkbVolume.Value.ToString();
        }

        /// <summary>
        /// 音量值改变完了事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tkbVolume_ValueChanged(object sender, EventArgs e)
        {
            SMS.Properties.Settings.Default.VOICE_VOLUME = this.tkbVolume.Value * 10;
            SMS.Properties.Settings.Default.Save();
        }
    }
}
